#include "StdAfx.h"
#include "ProjectSetupForm.h"

using namespace OgreUnified;

ProjectSetupForm::ProjectSetupForm()
{
	InitializeComponent();
	mInstance = this;
}

ProjectSetupForm^ ProjectSetupForm::Instance::get()
{
	return mInstance;
}

ProjectSetupForm::~ProjectSetupForm()
{
	if (components)
	{
		delete components;
	}
}

DialogResult ProjectSetupForm::ShowDialog(bool create)
{
	if(create)
	{
		mTabControl->SelectTab(mTabPageCreate);
	}
	return System::Windows::Forms::Form::ShowDialog();
}

System::Void ProjectSetupForm::mButtonBrowse_Click(System::Object^  sender, System::EventArgs^  e)
{
	FolderBrowserDialog^ folderbrowser = gcnew FolderBrowserDialog();
	if(System::Windows::Forms::DialogResult::OK == folderbrowser->ShowDialog())
	{
		mTextBoxLocation->Text = folderbrowser->SelectedPath;
	}
}

System::Void ProjectSetupForm::mButtonCreate_Click(System::Object^  sender, System::EventArgs^  e)
{
	try
	{
		if(System::IO::Directory::Exists(mTextBoxLocation->Text)==false)
		{
			System::IO::DirectoryInfo^ info = System::IO::Directory::CreateDirectory(mTextBoxLocation->Text);
		}
		
		Hide();
	}
	catch(System::Exception^ e)
	{
		MessageBox::Show(e->Message);
		ConsoleForm::Instance->logMessage(e->Message, LOG_ERROR);
	}
}

System::Void ProjectSetupForm::mButtonOpenOther_Click(System::Object^  sender, System::EventArgs^  e)
{

}

System::Void ProjectSetupForm::mButtonOpen_Click(System::Object^  sender, System::EventArgs^  e)
{

}

void ProjectSetupForm::InitializeComponent(void)
{
	this->mTabControl = (gcnew System::Windows::Forms::TabControl());
	this->mTabPageOpen = (gcnew System::Windows::Forms::TabPage());
	this->mListBox = (gcnew System::Windows::Forms::ListBox());
	this->mButtonOpenOther = (gcnew System::Windows::Forms::Button());
	this->mLabelSelectProject = (gcnew System::Windows::Forms::Label());
	this->mButtonOpen = (gcnew System::Windows::Forms::Button());
	this->mTabPageCreate = (gcnew System::Windows::Forms::TabPage());
	this->mButtonBrowse = (gcnew System::Windows::Forms::Button());
	this->mListBoxPackages = (gcnew System::Windows::Forms::ListBox());
	this->mTextBoxLocation = (gcnew System::Windows::Forms::TextBox());
	this->mLabelPackage = (gcnew System::Windows::Forms::Label());
	this->mLabelProjectLocation = (gcnew System::Windows::Forms::Label());
	this->mButtonCreate = (gcnew System::Windows::Forms::Button());
	this->mTabControl->SuspendLayout();
	this->mTabPageOpen->SuspendLayout();
	this->mTabPageCreate->SuspendLayout();
	this->SuspendLayout();
	// 
	// mTabControl
	// 
	this->mTabControl->Controls->Add(this->mTabPageOpen);
	this->mTabControl->Controls->Add(this->mTabPageCreate);
	this->mTabControl->Dock = System::Windows::Forms::DockStyle::Fill;
	this->mTabControl->Location = System::Drawing::Point(0, 0);
	this->mTabControl->Name = L"mTabControl";
	this->mTabControl->SelectedIndex = 0;
	this->mTabControl->Size = System::Drawing::Size(624, 442);
	this->mTabControl->TabIndex = 0;
	// 
	// mTabPageOpen
	// 
	this->mTabPageOpen->Controls->Add(this->mListBox);
	this->mTabPageOpen->Controls->Add(this->mButtonOpenOther);
	this->mTabPageOpen->Controls->Add(this->mLabelSelectProject);
	this->mTabPageOpen->Controls->Add(this->mButtonOpen);
	this->mTabPageOpen->Location = System::Drawing::Point(4, 22);
	this->mTabPageOpen->Name = L"mTabPageOpen";
	this->mTabPageOpen->Padding = System::Windows::Forms::Padding(3);
	this->mTabPageOpen->Size = System::Drawing::Size(616, 416);
	this->mTabPageOpen->TabIndex = 0;
	this->mTabPageOpen->Text = L"Open Project";
	this->mTabPageOpen->UseVisualStyleBackColor = true;
	// 
	// mListBox
	// 
	this->mListBox->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) 
		| System::Windows::Forms::AnchorStyles::Left) 
		| System::Windows::Forms::AnchorStyles::Right));
	this->mListBox->FormattingEnabled = true;
	this->mListBox->Location = System::Drawing::Point(11, 47);
	this->mListBox->Name = L"mListBox";
	this->mListBox->Size = System::Drawing::Size(597, 316);
	this->mListBox->TabIndex = 4;
	// 
	// mButtonOpenOther
	// 
	this->mButtonOpenOther->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left));
	this->mButtonOpenOther->Location = System::Drawing::Point(11, 383);
	this->mButtonOpenOther->Name = L"mButtonOpenOther";
	this->mButtonOpenOther->Size = System::Drawing::Size(91, 25);
	this->mButtonOpenOther->TabIndex = 3;
	this->mButtonOpenOther->Text = L"Open other...";
	this->mButtonOpenOther->UseVisualStyleBackColor = true;
	this->mButtonOpenOther->Click += gcnew System::EventHandler(this, &ProjectSetupForm::mButtonOpenOther_Click);
	// 
	// mLabelSelectProject
	// 
	this->mLabelSelectProject->AutoSize = true;
	this->mLabelSelectProject->Location = System::Drawing::Point(8, 20);
	this->mLabelSelectProject->Name = L"mLabelSelectProject";
	this->mLabelSelectProject->Size = System::Drawing::Size(154, 13);
	this->mLabelSelectProject->TabIndex = 2;
	this->mLabelSelectProject->Text = L"Select recently opened project:";
	// 
	// mButtonOpen
	// 
	this->mButtonOpen->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right));
	this->mButtonOpen->Location = System::Drawing::Point(517, 383);
	this->mButtonOpen->Name = L"mButtonOpen";
	this->mButtonOpen->Size = System::Drawing::Size(91, 25);
	this->mButtonOpen->TabIndex = 1;
	this->mButtonOpen->Text = L"Open";
	this->mButtonOpen->UseVisualStyleBackColor = true;
	this->mButtonOpen->Click += gcnew System::EventHandler(this, &ProjectSetupForm::mButtonOpen_Click);
	// 
	// mTabPageCreate
	// 
	this->mTabPageCreate->Controls->Add(this->mButtonBrowse);
	this->mTabPageCreate->Controls->Add(this->mListBoxPackages);
	this->mTabPageCreate->Controls->Add(this->mTextBoxLocation);
	this->mTabPageCreate->Controls->Add(this->mLabelPackage);
	this->mTabPageCreate->Controls->Add(this->mLabelProjectLocation);
	this->mTabPageCreate->Controls->Add(this->mButtonCreate);
	this->mTabPageCreate->Location = System::Drawing::Point(4, 22);
	this->mTabPageCreate->Name = L"mTabPageCreate";
	this->mTabPageCreate->Padding = System::Windows::Forms::Padding(3);
	this->mTabPageCreate->Size = System::Drawing::Size(616, 416);
	this->mTabPageCreate->TabIndex = 1;
	this->mTabPageCreate->Text = L"Create Project";
	this->mTabPageCreate->UseVisualStyleBackColor = true;
	// 
	// mButtonBrowse
	// 
	this->mButtonBrowse->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
	this->mButtonBrowse->Location = System::Drawing::Point(517, 28);
	this->mButtonBrowse->Name = L"mButtonBrowse";
	this->mButtonBrowse->Size = System::Drawing::Size(91, 25);
	this->mButtonBrowse->TabIndex = 7;
	this->mButtonBrowse->Text = L"Browse. . .";
	this->mButtonBrowse->UseVisualStyleBackColor = true;
	this->mButtonBrowse->Click += gcnew System::EventHandler(this, &ProjectSetupForm::mButtonBrowse_Click);
	// 
	// mListBoxPackages
	// 
	this->mListBoxPackages->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) 
		| System::Windows::Forms::AnchorStyles::Left) 
		| System::Windows::Forms::AnchorStyles::Right));
	this->mListBoxPackages->FormattingEnabled = true;
	this->mListBoxPackages->Location = System::Drawing::Point(11, 79);
	this->mListBoxPackages->Name = L"mListBoxPackages";
	this->mListBoxPackages->Size = System::Drawing::Size(597, 290);
	this->mListBoxPackages->TabIndex = 6;
	// 
	// mTextBoxLocation
	// 
	this->mTextBoxLocation->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left) 
		| System::Windows::Forms::AnchorStyles::Right));
	this->mTextBoxLocation->AutoCompleteMode = System::Windows::Forms::AutoCompleteMode::Suggest;
	this->mTextBoxLocation->AutoCompleteSource = System::Windows::Forms::AutoCompleteSource::FileSystemDirectories;
	this->mTextBoxLocation->Location = System::Drawing::Point(11, 31);
	this->mTextBoxLocation->Name = L"mTextBoxLocation";
	this->mTextBoxLocation->Size = System::Drawing::Size(500, 20);
	this->mTextBoxLocation->TabIndex = 5;
	// 
	// mLabelPackage
	// 
	this->mLabelPackage->AutoSize = true;
	this->mLabelPackage->Location = System::Drawing::Point(8, 63);
	this->mLabelPackage->Name = L"mLabelPackage";
	this->mLabelPackage->Size = System::Drawing::Size(151, 13);
	this->mLabelPackage->TabIndex = 4;
	this->mLabelPackage->Text = L"Import the following packages:";
	// 
	// mLabelProjectLocation
	// 
	this->mLabelProjectLocation->AutoSize = true;
	this->mLabelProjectLocation->Location = System::Drawing::Point(8, 15);
	this->mLabelProjectLocation->Name = L"mLabelProjectLocation";
	this->mLabelProjectLocation->Size = System::Drawing::Size(87, 13);
	this->mLabelProjectLocation->TabIndex = 3;
	this->mLabelProjectLocation->Text = L"Project Location:";
	// 
	// mButtonCreate
	// 
	this->mButtonCreate->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right));
	this->mButtonCreate->Location = System::Drawing::Point(517, 383);
	this->mButtonCreate->Name = L"mButtonCreate";
	this->mButtonCreate->Size = System::Drawing::Size(91, 25);
	this->mButtonCreate->TabIndex = 2;
	this->mButtonCreate->Text = L"Create";
	this->mButtonCreate->UseVisualStyleBackColor = true;
	this->mButtonCreate->Click += gcnew System::EventHandler(this, &ProjectSetupForm::mButtonCreate_Click);
	// 
	// ProjectSetupForm
	// 
	this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
	this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
	this->ClientSize = System::Drawing::Size(624, 442);
	this->Controls->Add(this->mTabControl);
	this->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
		static_cast<System::Byte>(0)));
	this->Name = L"ProjectSetupForm";
	this->Text = L"Project Wizard";
	this->mTabControl->ResumeLayout(false);
	this->mTabPageOpen->ResumeLayout(false);
	this->mTabPageOpen->PerformLayout();
	this->mTabPageCreate->ResumeLayout(false);
	this->mTabPageCreate->PerformLayout();
	this->ResumeLayout(false);

}